home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / info-service / www / src / WWW / Daemon / Implementation / HTRetrieve.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-26  |  3.3 KB  |  137 lines

  1. /*        Handle a Retrieve request from a WWW client    HTRetrieve.c
  2. **        ===========================================
  3. **
  4. ** Authors
  5. **    CTB    Carl Barker, Brunel
  6. **    DMX    Daniel Martin
  7. **    TBL    Tim Berners-Lee, CERN, Geneva    timbl@info.cern.ch
  8. **
  9. ** History:
  10. **    29 Apr 91 (TBL)    Split from daemon.c
  11. **    5 Sept 91 (DMX)    Added path simplification to prevent '..'ing to an 
  12. **            uncorrect directory.
  13. **            Added '\r' as space for telneting to socket.
  14. **    10 Sep 91 (TBL)    Reject request and log if fails authorisation
  15. **    26 Jan 92 (TBL) Added some of CTB's code for directory read.
  16. **     23 Ap 93 (TBL) keyword untangling passed to lower level
  17. */
  18.  
  19. /* (c) CERN WorldWideWeb project 1990,91. See Copyright.html for details */
  20.  
  21. #define USE_PLAINTEXT    /* Makes retrieval of postscript easier for now */
  22.             /* but not good sgml */
  23.  
  24. #define BUFFER_SIZE 4096    /* Arbitrary size for efficiency */
  25. #define INFINITY 512        /* file name length @@ FIXME */
  26.  
  27. #include "HTUtils.h"
  28. #include "HTFormat.h"
  29. #include "tcp.h"
  30.  
  31. #ifdef RULES            /* Use rules? */
  32. #include "HTRules.h"
  33. #endif
  34. #include "HTParse.h"
  35.  
  36. #include "HTFile.h"
  37. #include "HTDaemon.h"        /* calls back to HTTP daemon */
  38. #include "HTMLGen.h"        /* For HTML generator */
  39. #include "HTWriter.h"        /* For making streams to net and disk */
  40.  
  41. #include "HTAccess.h"
  42.  
  43. extern int WWW_TraceFlag;    /* Control diagnostic output */
  44. extern FILE * logfile;        /* Log file output */
  45. /* extern char HTClientHost[16]; */    /* Client name to be output */
  46. extern int HTWriteASCII PARAMS((int soc, char * s));    /* In HTDaemon.c */
  47.  
  48. /* PUBLIC FILE * logfile = 0;    */ /* Log file if any */
  49. extern char *HTClientHost;    /* Peer internet address */
  50.  
  51.  
  52.  
  53.  
  54.  
  55. /*    Override HTML presentation method
  56. **    ---------------------------------
  57. **
  58. **    The "presentation" of HTML in the case of a server is
  59. **    the generation of HTML markup.   The presence of this
  60. **    routine prevents any of the client-oriented presentation code
  61. **    from being picked up from the library libwww.
  62. */
  63. PUBLIC HTStructured* HTML_new ARGS3(
  64.     HTParentAnchor *,     anchor,
  65.     HTFormat,        format_out,
  66.     HTStream*,        stream)
  67. {
  68.     HTStream * markup = HTStreamStack(
  69.         WWW_HTML, format_out, stream, anchor);
  70.     if (!markup) return NULL;
  71.     
  72.     return HTMLGenerator(markup);
  73. }
  74.  
  75.  
  76. /*    Dummy things in hypertext object @@@@ */
  77.  
  78. PUBLIC void HText_select() {}
  79. PUBLIC void HText_selectAnchor() {}
  80. PUBLIC void * HTMainAnchor = NULL;
  81.  
  82.  
  83.  
  84. /*    Retrieve a document
  85. **    -------------------
  86. */
  87. #ifdef __STDC__
  88. int HTRetrieve(const char * arg,  int soc)
  89. #else
  90. int HTRetrieve(arg, soc)
  91.     char *arg;
  92.     int soc;
  93. #endif
  94. {
  95.  
  96.     char * arg2 = 0;    /* Simplified argument */
  97.     char * keywords=strchr(arg, '?');
  98.     
  99. #ifdef NOSEARCH
  100.     if (keywords) {
  101.     *keywords++ = 0;        /* Chop keywords off */
  102.     if (!*keywords) keywords = NULL;
  103.     else {
  104.         char *p;
  105.         for (p=keywords; *p; p++) if (*p == '+') *p = ' ';
  106.         /* Plusses to spaces */
  107.         HTUnEscape(keywords);
  108.     }
  109.     }
  110.     
  111.     if (keywords) {
  112.     if (TRACE) printf("HTHandle: can't perform search %s\n",
  113.         arg);
  114.     return HTLoadError(HTASCIIWriter(soc), 403,
  115.         "Sorry, this server does not perform searches.");
  116.         /* It ought to, using an executable script */
  117.     }
  118. #endif
  119.  
  120.     StrAllocCopy(arg2, arg);
  121.     HTSimplify(arg2);    /* Remove ".." etc  (DMX) */
  122.  
  123.  
  124. /*        Load the document into the client
  125. */
  126.     {
  127.     HTStream * client = HTASCIIWriter(soc);
  128.  
  129.     HTLoadToStream(arg2, NO, client);
  130.     free(arg2);
  131.     return HT_LOADED;
  132.     }
  133.  
  134. } /* Retrieve */
  135.  
  136.  
  137.